package com.zk5_education.service_edu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zk5_education.R;
import com.zk5_education.service_edu.entity.EduVideo;
import com.zk5_education.service_edu.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-08-08
 */
@RestController
@RequestMapping("/service_edu/edu_video")
@CrossOrigin
public class EduVideoController {
    @Autowired
    EduVideoService eduVideoService;

    //删除小节
    @PostMapping("deletevideo/{videoid}")
    public R DeleteVideo(@PathVariable String videoid){
        eduVideoService.removeById(videoid);
        return R.success();
    }

    //添加小节
    @PostMapping ("/addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.save(eduVideo);
        return R.success();
    }

    //修改小节
    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.save(eduVideo);
        return R.success();
    }
    //查询小节
    @GetMapping("/selectVideo/{videoid}")
    public R SelectVideo(@PathVariable String videoid){

        EduVideo video = eduVideoService.getById(videoid);
        return R.success().data("video",video);
    }
    //根据课程查询所有视频的来源

    @GetMapping("selectVideo/{courseid}")
    public R selectVideo(@PathVariable String courseid){

        QueryWrapper<EduVideo>qy=new QueryWrapper<>();
        qy.select("video_source_id");
        qy.eq("course_id",courseid);
        List<EduVideo> list = eduVideoService.list(qy);
        return R.success().data("list",list);
    }
}

